import JsonData from "../../Json.js";
let { brideName, groomName, sharePhoto, musicUrl } = JsonData.invite;
Page({
  data: {
    hiddenLoading: false,
    indicatorDots: false,
    autoplay: false,
    circular: false,
    current: 0,
    interval: 5000,
    duration: 1000,   
    currentIndex: 0,
    windowWidth: 0,
    isPlayMusic: false,
    musicPlayIcon: "http://qnm.hunliji.com/o_1c0639gngphd50v1jp81dqav40u.png",
    controls: false,
    src: musicUrl
  },
  changeIndicatorDots: function (t) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    });
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    });
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    });
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    });
  },
  getCurrentIndex: function (e) {
    this.setData({
      currentIndex: e.detail.current
    });
  },

  listenerMusicBtn: function () {
    this.setData({
      isPlayMusic: !this.data.isPlayMusic
    });
    if (this.data.isPlayMusic) {
      this.setData({
        musicPlayIcon: "http://qnm.hunliji.com/o_1c0639gngphd50v1jp81dqav40u.png"
      });
      this.audioCtx.play();
    } else{
      this.setData({
        musicPlayIcon: "http://qnm.hunliji.com/o_1c0639k31jljg131r1pfpb1j2n13.png"
      });
      this.audioCtx.pause();
    }

  },
  onLoad: function () {
    let than = this;
    wx.getSystemInfo({
      success: function (e) {
        console.log(e);
         than.setData({
          windowWidth: e.windowWidth
        });
      }
    });
    this.setData({
      hiddenLoading: false
    });
  },
  onReady: function () {
    this.audioCtx = wx.createAudioContext("myAudio");
    this.audioCtx.play();
    this.setData({
      hiddenLoading: true,
      isPlayMusic: true
    });
  },
  onShareAppMessage: function (e) {
    return "button" === e.from && console.log(e.target), {
      title: `${brideName}&${groomName}的结婚邀请函`,
      path: "pages/index/index",
      imageUrl: sharePhoto,
      success: function (res) {
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (err) {
        console.log("转发失败:" + JSON.stringify(err));
      }
    };
  }
});